#ifndef _COLOR_H_
#define _COLOR_H_

#include "./visual_define.h"
#include "./color_space_rgba.h"

namespace Visual {

	using namespace ColorSpace;
	//! Color
	/*!
		RGB Color
	*/
	class Color: public Wtb {
	private:
		/*! maximum component */
		static const double max_comp;
		/*! spatial dimension */
		static const usint spt_dim = 3;
		/*! color coordinates */
		double *coord;

		void copy(const Color &original);
		bool create();
		void free();
		void verify();

	public:

		Color ( const double &red = 0.0, const double &green = 0.0, const double &blue = 0.0, const double &alpha = 1.0 );
		Color ( const Color &original );
		virtual ~Color();
			
		inline void setColorRGB( const double &r, const double &g, const double &b, const double &a = 1.0 ) {
			coord[R] = r;	coord[G] = g;	coord[B] = b; coord[A] = a;
			verify();
		};
		//inline void setColorCMY( const double &c, const double &m, const double &y ) {
		//	using namespace Mathematics;
		//	coord[0] = max_comp-c;	coord[1] = max_comp-m;	coord[2] = max_comp-y;
		//	verify();
		//};
		//void setColorHSV( const double &h, const double &s, const double &v ) ;

		inline double& operator[]( const usint &index ) const {
			if( index >= spt_dim )
				throw OutOfBoundsException( "Invalid access!", spt_dim, index );
			return coord[index];
		};
		inline double& operator[]( const CoordinateRGBA &index ) const {
			return coord[(int)index];
		};

		inline virtual string toS() const {
			string result = "( ";
			for( usint i = 0; i < spt_dim; ++i )
				result += dtos( coord[i] ) + " ";
			return result + ")";
		};

		Color& operator = ( const Color &col ) ;
		Color operator + ( const Color &col ) const ;
		Color& operator += ( const Color &col ) ;
		Color operator - ( const Color &col ) const ;
		Color& operator -= ( const Color &col ) ;
		Color operator * ( const double &value ) const ;
		Color& operator *= ( const double &value ) ;
		Color operator / ( const double &value ) const ;
		Color& operator /= ( const double &value ) ;

		virtual bool filePrint( FILE *parq = stdin ) const ;
			
		double* toPointerd() const ;
		float* toPointerf() const ;
			
	};

};

#endif // _COLOR_H_
